add list code for lan/wan dns
authorFelix Fietkau <[email protected]>
Fri, 30 Sep 2005 23:27:06 +0000 (23:27 +0000)
committerFelix Fietkau <[email protected]>
Fri, 30 Sep 2005 23:27:06 +0000 (23:27 +0000)
SVN-Revision: 2013

openwrt/package/webif/files/usr/lib/webif/form.awk
openwrt/package/webif/files/usr/lib/webif/webif.sh
openwrt/package/webif/files/www/cgi-bin/webif/lan.sh
openwrt/package/webif/files/www/cgi-bin/webif/wan.sh
openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh

index 8a405bcb98a2ae915edde2c85a9fc3a9be5f2155..b402285000dbe88153f2c5ac697220b4f04a8325 100644 (file)
@@ -62,7 +62,7 @@ $1 ~ /^select/ {
 ($1 ~ /^listedit/) {
        n = split($4 " ", items, " ")
        for (i = 1; i <= n; i++) {
-               if (items[i] != "") print "<tr><td width=\"50%\">" items[i] "</td><td>&nbsp;<a href=\"" $3 "?" $2 "remove=" items[i] "\">Remove</a></td></tr>"
+               if (items[i] != "") print "<tr><td width=\"50%\">" items[i] "</td><td>&nbsp;<a href=\"" $3 $2 "remove=" items[i] "\">Remove</a></td></tr>"
        }
        print "<tr><td width=\"100%\" colspan="2"><input type=\"text\" name=\"" $2 "add\" value=\"" $5 "\" /><input type=\"submit\" name=\"" $2 "submit\" value=\"Add\" /></td></tr>"
 }
index 445b234ec6859c71fe18a6b4e64fc1436bea045c..43f54b006716e118a1a01013dd52a292b71589b5 100644 (file)
@@ -181,11 +181,9 @@ list_remove() {
 BEGIN {
        RS=" "
        FS=":"
-       first = 1
 }
-($0 !~ /^'"$2"'/) {
-       if (first != 1) printf " "
-       printf $0
+($0 !~ /^'"$2"'/) && ($0 != "") {
+       printf " " $0
        first = 0
 }'
 }
@@ -194,12 +192,17 @@ handle_list() {
        _new="${1:+$(list_remove "$LISTVAL" "$1") }"
        _new="${_new:-$LISTVAL}"
        LISTVAL="$_new"
+       LISTVAL="${LISTVAL# }"
+       LISTVAL="${LISTVAL%% }"
        
        _validate="$4"
        _validate="${4:-none}"
-       [ \! -z "$3" ] && validate "$_validate|$2" && LISTVAL="$LISTVAL $2"
+       _changed="$1"
+       [ \! -z "$3" ] && validate "$_validate|$2" && {
+               LISTVAL="$LISTVAL $2"
+               _changed="$1$3"
+       }
 
-       _changed="$1$3"
        _return="${_changed:+0}"
        _return="${_return:-255}"
        LISTVAL="${LISTVAL# }"
@@ -221,8 +224,11 @@ save_setting() {
        mkdir -p /tmp/.webif
        oldval=$(eval "echo \${$2}")
        oldval=${oldval:-$(nvram get "$2")}
-       mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&-
-       grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&-
+       grep "^$2=" /tmp/.webif/config-$1 >&- 2>&- && {
+               mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&-
+               grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&- 
+               oldval=""
+       }
        [ "$oldval" != "$3" ] && echo "$2=\"$3\"" >> /tmp/.webif/config-$1
        rm -f /tmp/.webif/config-$1-old
 }
index 9eee53d8072cd401bf5f2af85bdad96f6321152d..d9fd7759e6ab4c1d4adbf99336557c672010c633 100755 (executable)
@@ -3,12 +3,20 @@
 . /usr/lib/webif/webif.sh
 load_settings network
 
-[ -z $FORM_submit ] && {
+FORM_dns="${lan_dns:-$(nvram get lan_dns)}"
+LISTVAL="$FORM_dns"
+handle_list "$FORM_dnsremove" "$FORM_dnsadd" "$FORM_dnssubmit" 'ip|FORM_dnsadd|LAN DNS address|required' && {
+       FORM_dns="$LISTVAL"
+       save_setting network lan_dns "$FORM_dns"
+}
+FORM_dnsadd=${FORM_dnsadd:-192.168.1.1}
+
+
+if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then
        FORM_lan_ipaddr=${lan_ipaddr:-$(nvram get lan_ipaddr)}
        FORM_lan_netmask=${lan_netmask:-$(nvram get lan_netmask)}
        FORM_lan_gateway=${lan_gateway:-$(nvram get lan_gateway)}
-       FORM_lan_dns=${lan_dns:-$(nvram get lan_dns)}
-} || {
+else
        SAVED=1
        validate "
 ip|FORM_lan_ipaddr|LAN IP|required|$FORM_lan_ipaddr
@@ -17,9 +25,8 @@ ip|FORM_lan_gateway|LAN gateway||$FORM_lan_gateway" && {
                save_setting network lan_ipaddr $FORM_lan_ipaddr
                save_setting network lan_netmask $FORM_lan_netmask
                save_setting network lan_gateway $FORM_lan_gateway
-               save_setting network lan_dns $FORM_lan_dns
        }
-}
+fi
 
 header "Network" "LAN" "LAN settings" '' "$SCRIPT_NAME"
 
@@ -30,8 +37,11 @@ field|Netmask
 text|lan_netmask|$FORM_lan_netmask
 field|Default Gateway
 text|lan_gateway|$FORM_lan_gateway
-field|DNS Server
-text|lan_dns|$FORM_lan_dns
+end_form
+start_form|DNS Servers
+listedit|dns|$SCRIPT_NAME?|$FORM_dns|$FORM_dnsadd
+helpitem|Note
+helptext|You should save your settings on this page before adding/removing DNS servers
 end_form" 
 
 footer ?>
index c9a64691e9c20038f1a40c44832e463fc2458252..60a930de296075e72d63134dd06463be2968649c 100755 (executable)
@@ -4,6 +4,15 @@
 
 load_settings network
 
+FORM_dns="${wan_dns:-$(nvram get wan_dns)}"
+LISTVAL="$FORM_dns"
+handle_list "$FORM_dnsremove" "$FORM_dnsadd" "$FORM_dnssubmit" 'ip|FORM_dnsadd|WAN DNS address|required' && {
+       FORM_dns="$LISTVAL"
+       save_setting network wan_dns "$FORM_dns"
+}
+FORM_dnsadd=${FORM_dnsadd:-192.168.1.1}
+
+
 [ -z $FORM_submit ] && {
        FORM_wan_proto=${wan_proto:-$(nvram get wan_proto)}
        case "$FORM_wan_proto" in
@@ -27,7 +36,6 @@ text|pptp_server_ip|$FORM_pptp_server_ip"
        FORM_wan_ipaddr=${wan_ipaddr:-$(nvram get wan_ipaddr)}
        FORM_wan_netmask=${wan_netmask:-$(nvram get wan_netmask)}
        FORM_wan_gateway=${wan_gateway:-$(nvram get wan_gateway)}
-       FORM_wan_dns=${wan_dns:-$(nvram get wan_dns)}
        
        # ppp common
        FORM_ppp_username=${ppp_username:-$(nvram get ppp_username)}
@@ -76,7 +84,6 @@ ip|FORM_pptp_server_ip|PPTP server IP|$V_PPTP|$FORM_pptp_server_ip" && {
                # Settings specific to one protocol type
                case "$FORM_wan_proto" in
                        static)
-                               save_setting network wan_dns $FORM_wan_dns
                                save_setting network wan_gateway $FORM_wan_gateway
                                ;;
                        pptp)
@@ -121,6 +128,7 @@ function modechange()
 {
        var v;
        v = (checked('wan_proto_pppoe') || checked('wan_proto_pptp'));
+       set_visible('ppp_settings', v);
        set_visible('ppp_username', v);
        set_visible('ppp_passwd', v);
        set_visible('ppp_redial', v);
@@ -129,6 +137,7 @@ function modechange()
        set_visible('ppp_persist_redialperiod', v && !checked('ppp_redial_demand'));
        
        v = (checked('wan_proto_static') || checked('wan_proto_pptp') || checked('wan_proto_dhcp'));
+       set_visible('ip_settings', v);
        set_visible('wan_ipaddr', v);
        set_visible('wan_netmask', v);
        
@@ -145,17 +154,25 @@ radio|wan_proto|$FORM_wan_proto|dhcp|DHCP<br />|onchange=\"modechange()\"
 radio|wan_proto|$FORM_wan_proto|static|Static IP<br />|onchange=\"modechange()\"
 $PPPOE_OPTION
 $PPTP_OPTION
+end_form
 
+start_form|IP Settings|ip_settings|hidden
 field|Internet IP Address|wan_ipaddr|hidden
 text|wan_ipaddr|$FORM_wan_ipaddr
 field|Subnet Mask|wan_netmask|hidden
 text|wan_netmask|$FORM_wan_netmask
 field|Gateway|wan_gateway|hidden
 text|wan_gateway|$FORM_wan_gateway
-field|DNS Server(s)|wan_dns|hidden
-text|wan_dns|$FORM_wan_dns
 $PPTP_SERVER_OPTION
+end_form
+
+start_form|DNS Servers|wan_dns|hidden
+listedit|dns|$SCRIPT_NAME?wan_proto=static&|$FORM_dns|$FORM_dnsadd
+helpitem|Note
+helptext|You should save your settings on this page before adding/removing DNS servers
+end_form
 
+start_form|PPP Settings|ppp_settings|hidden
 field|PPP Redial Policy|ppp_redial|hidden
 radio|ppp_redial|$FORM_ppp_redial|demand|Connect on Demand<br />|onChange=\"modechange()\"
 radio|ppp_redial|$FORM_ppp_redial|persist|Keep Alive|onChange=\"modechange()\"
@@ -169,9 +186,9 @@ field|PPP Password|ppp_passwd|hidden
 text|ppp_passwd|$FORM_ppp_passwd
 field|PPP MTU|ppp_mtu|hidden
 text|ppp_mtu|$FORM_ppp_mtu
-end_form" ?>
+end_form" 
 
-<? footer ?>
+footer ?>
 <!--
 ##WEBIF:name:Network:2:WAN
 -->
index ddc44f62a139fc8d6c1b2ea3d4a269e7947dd688..17d90a763fe081b03d1719bfe413e834cb7840bc 100755 (executable)
@@ -3,13 +3,11 @@
 . /usr/lib/webif/webif.sh
 load_settings "wireless"
 
-
 FORM_wds="${wl0_wds:-$(nvram get wl0_wds)}"
 LISTVAL="$FORM_wds"
 handle_list "$FORM_wdsremove" "$FORM_wdsadd" "$FORM_wdssubmit" 'mac|FORM_wdsadd|WDS MAC address|required' && {
        FORM_wds="$LISTVAL"
        save_setting wireless wl0_wds "$FORM_wds"
-       FORM_submit=""
 }
 FORM_wdsadd=${FORM_wdsadd:-00:00:00:00:00:00}
 
@@ -24,7 +22,7 @@ for ch in $CHANNELS; do
 "
 done
 
-if [ -z "$FORM_submit" ]; then
+if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then
        FORM_mode=${wl0_mode:-$(nvram get wl0_mode)}
        FORM_ssid=${wl0_ssid:-$(nvram get wl0_ssid)}
        FORM_channel=${wl0_channel:-$(nvram get wl0_channel)}
@@ -226,7 +224,9 @@ radio|key|$FORM_key|4
 text|key4|$FORM_key4|<br />
 end_form
 start_form|WDS connections
-listedit|wds|$SCRIPT_NAME|$FORM_wds|$FORM_wdsadd
+listedit|wds|$SCRIPT_NAME?|$FORM_wds|$FORM_wdsadd
+helpitem|Note
+helptext|You should save your settings on this page before adding/removing WDS links
 end_form"
 
 footer ?>